<?php
/**
 * ============================================================================
 * 版权所有 2008-2011 多多网络，并保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

include('comm/tuaninc.php');

if(TGOPEN==0){
    header("location:index.php");
}

function param($get='',$val=''){
	global $tuan_cat_id;
	global $city_id;
	global $mall_id;
    switch($get){
	    case 'catid':
		    if(WJT==1){
			    return "tg-".$city_id."-".$val."-".$mall_id.'.html';
			}else{
			    return "tg.php?city_id=".$city_id."&catid=".$val."&mallid=".$mall_id;
			}
		    
		break;
		case 'city_id':
		    if(WJT==1){
				return "tg-".$val."-".$tuan_cat_id."-".$mall_id.'.html';
			}else{
			    return "tg.php?city_id=".$val."&catid=".$tuan_cat_id."&mallid=".$mall_id;
			}
		    
		break;
		case 'mallid':
		    if(WJT==1){
				return "tg-".$city_id."-".$tuan_cat_id."-".$val.'.html';
			}
			else{
			    return "tg.php?city_id=".$city_id."&catid=".$tuan_cat_id."&mallid=".$val;
			}
		break;
		case '':
		    if(WJT==1){
			    return "tg-".$city_id."-".$tuan_cat_id."-".$mall_id.'.html';
			}
			else{
			    return "tg.php?city_id=".$city_id."&catid=".$tuan_cat_id."&mallid=".$mall_id;
			}
		break;
	}
}

//参数检测
$id=empty($_GET['id'])?0:intval($_GET['id']);

//热门搜索
$hot_arr=explode('|',$hot_words);

//商品数据
$sql="select a.id,a.local,a.city,a.title,a.catname,a.mall_id,a.image,a.startTime,a.endTime,a.value,a.price,a.rebate,a.bought,b.name,b.logo,b.id as mallid,b.fan,b.url from ".$duoduo->BIAOTOU."tuan_goods as a,".$duoduo->BIAOTOU."mall as b where a.id='".$id."' and a.mall_id=b.id limit 1";
$arr=$duoduo->sqltoarr($sql,1);

if(!$arr['id']){
    echo ERR404;
	exit;
}

//全部团购商家
$sql="select id,name,fan from ".$duoduo->BIAOTOU."mall where catid = '".TUANCID."' and api_url is not null and api_url<>'' order by sort desc";
$malls=$duoduo->sqltoarr($sql);

//团购导航
$tuan_cat_arr['99']='全部';
$sql="select id,catename from ".$duoduo->BIAOTOU."catelist order by sortorder desc";
$query=$duoduo->query($sql);
while($row=$duoduo->fetch_array($query)){
    $tuan_cat_arr[$row['id']]=$row['catename'];
	$cat_arr[$row['id']]=$row['catename'];
}
$tuan_cat_id=$_GET['catid']?intval($_GET['catid']):99;
$tuan_cat_name=$tuan_cat_arr[$tuan_cat_id];

//城市
$cur_city=$arr['city'];
$city_id=$duoduo->sel_sql('city','cityid',"cityname='$cur_city'");

$city_sort_arr=include(CACHE.'city/city_sort.php');
$city_word_arr=include(CACHE.'city/city_word.php');

//本地团购
$sql="select a.title,a.price,a.id,b.name,b.fan,b.id as mallid from ".$duoduo->BIAOTOU."tuan_goods as a,".$duoduo->BIAOTOU."mall as b where a.mall_id=b.id and a.mall_id='".$arr['mall_id']."' and a.city='".$arr['city']."' order by a.id desc limit 0,3";
$state_tuan=$duoduo->sqltoarr($sql);
include('comm/wjt.php');
if(WJT==0){
	$url_head_city_id='.php?city_id=';
    $page_tuan_list=param()."&keyword=".urlencode($keyword);
}
else{
	$url_head_city_id='-';
    $page_tuan_list="tg-".$city_id."-".$tuan_cat_id."-".$mall_id."-".urlencode($keyword);
}

if($tuan_cat_name!='全部'){
    $tuan_cat_name_title=$tuan_cat_name.'|';
}
$tag='tg';
$pagetag='tgview';
include_once 'comm/seo.php';
include('template/'.MOBAN.'/tgview.tpl.php');
echo '<script type="text/javascript" src="http://'.URL.'/comm/auto.php"></script>';